package pms.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;


/** 
 * Controller to generate the Home Page basics to be rendered by a view. 
 * It extends the convenience class AbstractController that encapsulates most 
 * of the drudgery involved in handling HTTP requests. 
 * @author KRS DEV Team (krsdevteam@PMSWIbb2011SS.de)
 */
public class SaveEvent extends AlleEvents {
	protected ModelAndView handleRequestInternal(
			HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {
		
		httpServletRequest.setCharacterEncoding("UTF-8");
		int id = Integer.parseInt(httpServletRequest.getParameter("id"));
		
		String name = httpServletRequest.getParameter("name");
		String datum = httpServletRequest.getParameter("datum");
		String zeit = httpServletRequest.getParameter("zeit");
		String p1 = httpServletRequest.getParameter("preis_loge");
		String p2 = httpServletRequest.getParameter("preis_reg");
		int t_id = Integer.parseInt(httpServletRequest.getParameter("theater"));
		
						
		if (id == 0) {
			getEventDao().create(name, datum, zeit, p1, p2, t_id);
		} else {
			getEventDao().modify(id, name, datum, zeit, p1, p2, t_id);
		}
		return super.handleRequestInternal(httpServletRequest, httpServletResponse);
	}

}
